import { defineStore } from 'pinia'
import { getCookie, setCookie } from '@/utils/cookies'
import { routes } from '@/router/index'

const state = () => ({
  token: getCookie('USER_TOKEN'),
  info: getCookie('USER_INFO')
})

const actions = {
  setToken (token) {
    setCookie('USER_TOKEN', token)
    this.token = token
  },
  setInfo (info) {
    setCookie('USER_INFO', info)
    this.info = info
  },
  async generateRoutes () {
    return routes
  }
}

export default defineStore(
  'user',
  { state, actions }
)
